//===============================================================================
// Microsoft patterns & practices
// Web Client Software Factory
//-------------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//-------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WCSFContrib.PageFlow.WorkflowFoundation.Tests.Mocks;

namespace WCSFContrib.PageFlow.WorkflowFoundation.Tests
{
	[TestClass]
	public class WorkflowFoundationPageFlowFactoryFixture
	{
        [ClassInitialize]
        public static void SetupDatabase(TestContext testContext)
        {
            SetupDatabaseUtility.Setup();
        }

		[TestMethod]
		public void CanCreateWithOutParameters()
		{
			WorkflowFoundationPageFlowFactory factory = new WorkflowFoundationPageFlowFactory();
			Assert.IsNotNull(factory);
		}

        [TestMethod]
        public void GetPageflowByTypeCreatesNewInstance()
        {
            using (WorkflowFoundationPageFlowFactory factory = new WorkflowFoundationPageFlowFactory())
            {
                IPageFlow pageflow = factory.GetPageFlow(typeof(MockConstrainedPageFlow));
                Assert.IsNotNull(pageflow);
            }            
        }

        [TestMethod]
        public void GetPageflowByTypeCreatesDifferentInstancesEachTime()
        {
            using (WorkflowFoundationPageFlowFactory factory = new WorkflowFoundationPageFlowFactory())
            {
                IPageFlow pageflow1 = factory.GetPageFlow(typeof(MockConstrainedPageFlow));
                IPageFlow pageflow2 = factory.GetPageFlow(typeof(MockConstrainedPageFlow));

                Assert.AreNotSame(pageflow1, pageflow2);
                Assert.AreNotEqual(pageflow1, pageflow2);
            }
        }

        [TestMethod]
        public void GetPageflowByTypeAndThenByIdCreatesEqualInstances()
        {
            using (WorkflowFoundationPageFlowFactory factory = new WorkflowFoundationPageFlowFactory())
            {
                IPageFlow pageflow1 = factory.GetPageFlow(typeof(MockConstrainedPageFlow));
                IPageFlow pageflow2 = factory.GetPageFlow(typeof(MockConstrainedPageFlow), pageflow1.Id);

                Assert.AreNotSame(pageflow1, pageflow2);
                Assert.AreEqual(pageflow1, pageflow2);
            }
        }       
	}    
}
